import app from "../../app";
import { face_prop_item } from "../../shared/interface";
import { MsgAction, template, Tpl_propDefault_look } from "../../shared/master/MsgAction";
import { pet } from "../fight/body/pet";
import { player, wallet_key } from "../fight/body/player";
import { prop_base } from "./prop_base";

export class prop_PetEgg extends prop_base {
    data: any;
    constructor(data: face_prop_item) {
        super(data);
        this.data = data.data;
        this.haveSup = false;
    }
    getStrName(): string {
        return this.data.name
    }
    getStyleName(): string {
        return `🥚${this.data.name}`
    }
    /**
     * 查看道具
     * 返回 消息模板data
     * 
     */
    look(tag: player) {
        let data = this.data;

        let skillNames: string = '';
        let skills = data.skills.split(',')
        for (let i = 0; i < skills.length; i++) {
            const element = skills[i] as string;
            let name = '错误技能';
            let arry = element.split('-')
            if (arry[1]) {
                name = arry[1];
            } else {
                name = arry[0];
            }
            skillNames += `[${name}]`
        }
        let tpl: Tpl_propDefault_look = {
            name: data.name,
            from: this.from,
            cont: this.num,
            score: this.score,
            type: this.min_type,
            decs: `使用后将获得宠物:${data.name} 孵化后等级会保留,属性/技能会基于原本属性的基础变化。\n宠物技能一览${skillNames}`,
            icon: "",
            instruct_tips: '',
            instruct: ''
        }
        return { template: template.prop_info, data: tpl }
    }
    use(tag: player, num: number): boolean {
        this.num = 0;
        const maps = new Map();
        let data = this.data;
        maps.set('1', data)
        let leve = this.data.leve || tag.leve.num;
        let body = app.createUnity('1', leve, maps, this.score, 2) as pet;
        if(body.pets.length > 100){
            tag.sendMsg(template.default_none, `🥚宠物数量最多可拥有100个哦~`)
            return false;
        }
        tag.addPet(body);
        tag.sendMsg(template.default_none, `🥚已孵化宠物:${body.name}，快发送[宠物]给他起个名吧~`)
        return true;
    }
}